import 'package:flutter/material.dart';
import 'package:flutter_soundmagus/widget/widget.dart';

class ZFSwitch extends StatefulWidget {
  final bool on;
  final void Function(bool isOn)? onChange;
  const ZFSwitch({Key? key, this.on = false, this.onChange}) : super(key: key);

  @override
  _ZFSwitchState createState() => _ZFSwitchState();
}

class _ZFSwitchState extends State<ZFSwitch> {
  bool on = false;

  @override
  void initState() {
    super.initState();
    on = widget.on;
  }

  @override
  Widget build(BuildContext context) {
    return IconButton(
        icon: ImageExt.zfasset(on ? 'icon_switch_on' : 'icon_switch_off',
            width: 32, height: 18),
        onPressed: () {
          setState(() {
            on = !on;
          });
          widget.onChange?.call(on);
        });
  }
}
